#ifndef PLAYVOICE_H
#define PLAYVOICE_H

#include <QObject>
#include <QProcess>
#include <QTimerEvent>

namespace ns_yht
{

#define PLAYVOICE PlayVoice::instance()

    struct ModelMsg;

    class PlayVoice : public QObject
    {
        Q_OBJECT
    public:
        PlayVoice();
        ~PlayVoice();

        static PlayVoice *instance();

        enum class VoiceType
        {
            None = 0,
            SystemStart,
            SystemRunning,
            NetworkConnected,
            NetworkDisconnected,
            TokenReceived,
            TokenFailed,
            SystemClose,

            StartSystemUpdate,
            SystemUpdateSucceed,
            SystemUpdateFailed,

            StartRiskAreaUpdate,
            RiskAreaUpdateSucceed,
            RiskAreaUpdateFailed,

            Collision,
            RiskArea,

            BluetoothConnected,
            BluetoothDisconnected,
            BluetoothFailed,
            BluetoothWaiting,
            BluetoothClose,

            BridgePass,
            DutyCaution,

            Error
        };

        void start();

        void play(VoiceType type, quint64 id = 0);

        void timerEvent(QTimerEvent *event);
    public slots:
        void ensureCurrentMsgModel();
    private slots:
        void OnstandardOutput(QByteArray result);
        void onProcessError(QProcess::ProcessError error);

    private:
        QString getVoiceFile(VoiceType type, int id = 0);

        QProcess *m_process{nullptr};
        int m_timerId{0};
        int m_filterMode{0};
        ModelMsg *m_msgModel{nullptr};
        qint64 m_lastVoiceTime{0};

        static PlayVoice *m_instance;
    };

}
#endif